const state = {
  pending: "PENDING",
  fulfilled: "FULFILLED",
  rejected: "REJECTED",
};
class Promise {
  state = state.pending;
  value = undefined;
  reason = undefined;
  constructor(exectur) {
    const resolve = (value) => {
      if (this.state === state.pending) {
        this.value = value;
        this.state = state.fulfilled;
      }
    };
    const reject = (reason) => {
      if (this.state === state.pending) {
        this.reason = reason;
        this.state = state.rejected;
      }
    };
    exectur(resolve, reject);
  }

  then(onFufilled, onRejected) {
    if (this.state === state.fulfilled) {
      onFufilled(this.value);
    }

    if (this.state === state.rejected) {
      onRejected(this.reason);
    }
  }
}
export default Promise;
